package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.constant.EmpChangeType;
import org.jsola.hr.dto.EmpChangesAddDTO;
import org.jsola.hr.dto.EmpChangesUpdateDTO;
import org.jsola.hr.entity.EmpChangesDO;
import org.jsola.hr.query.EmpChangesQuery;
import org.jsola.hr.service.IEmpChangesService;
import org.jsola.hr.vo.EmpChangesVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class EmpChangesTestHelper extends BaseTestHelper {
    
    @Autowired
    private IEmpChangesService empChangesService;

    /**
     * 生成add测试数据
     * @return EmpChangesAddDTO
     */
    public EmpChangesAddDTO getEmpChangesAddDTO(){
        EmpChangesAddDTO empChangesAddDTO = new EmpChangesAddDTO();
        empChangesAddDTO.setEmpId(getRandomValue("varchar",32));
        empChangesAddDTO.setApproFlowId(getRandomValue("varchar",32));
        empChangesAddDTO.setChangeType(EmpChangeType.TRANSFER__FORMAL.getValue());
        empChangesAddDTO.setPreCode(getRandomValue("varchar",255));
        empChangesAddDTO.setCurrentCode(getRandomValue("varchar",255));
        empChangesAddDTO.setFormallyDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empChangesAddDTO.setProbationDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empChangesAddDTO.setRegularDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empChangesAddDTO.setRegularEvaluation(getRandomValue("varchar",2000));
        empChangesAddDTO.setRegularAttacment(getRandomValue("varchar",32));
        empChangesAddDTO.setAdjustmentDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empChangesAddDTO.setAdjustmentReason(getRandomValue("varchar",255));
        empChangesAddDTO.setAdjustmentAttachment(getRandomValue("varchar",32));
        empChangesAddDTO.setPreDep(getRandomValue("text",10000));
        empChangesAddDTO.setPrePosition(getRandomValue("text",10000));
        empChangesAddDTO.setPreLevel(SafeKit.getInteger(getRandomValue("int",11)));
        empChangesAddDTO.setPreSupervisor(getRandomValue("varchar",255));
        empChangesAddDTO.setPreManagerForm(SafeKit.getInteger(getRandomValue("tinyint",4)));
        empChangesAddDTO.setPreWorkCityId(getRandomValue("varchar",255));
        empChangesAddDTO.setCurrentDep(getRandomValue("varchar",255));
        empChangesAddDTO.setCompanyId(getRandomValue("varchar",32));
        empChangesAddDTO.setCurrentPosition(getRandomValue("varchar",255));
        empChangesAddDTO.setCurrentLevel(SafeKit.getInteger(getRandomValue("int",11)));
        empChangesAddDTO.setCurrentSupervisor(getRandomValue("varchar",255));
        empChangesAddDTO.setCurrentManagerForm(SafeKit.getInteger(getRandomValue("tinyint",4)));
        empChangesAddDTO.setCurrentWorkCityId(getRandomValue("varchar",255));
        empChangesAddDTO.setQuitType(SafeKit.getInteger(getRandomValue("tinyint",4)));
        empChangesAddDTO.setQuitDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empChangesAddDTO.setPreQuitDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empChangesAddDTO.setHandleQuitDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empChangesAddDTO.setPersonalReason(SafeKit.getInteger(getRandomValue("tinyint",4)));
        empChangesAddDTO.setCompanyReason(SafeKit.getInteger(getRandomValue("tinyint",4)));
        empChangesAddDTO.setQuitReason(getRandomValue("varchar",2000));
        empChangesAddDTO.setQuitRemarks(getRandomValue("varchar",2000));
        empChangesAddDTO.setApplyQuitReason(getRandomValue("varchar",2000));
        empChangesAddDTO.setCompensation(SafeKit.getInteger(getRandomValue("int",11)));
        empChangesAddDTO.setPaymentLieuNotice(SafeKit.getInteger(getRandomValue("int",11)));
        empChangesAddDTO.setSsAttritionMonth((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empChangesAddDTO.setPfAttritionMonth((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empChangesAddDTO.setSurplusYearHoliday(SafeKit.getInteger(getRandomValue("int",11)));
        empChangesAddDTO.setSurplusBreakOff(SafeKit.getInteger(getRandomValue("int",11)));
        empChangesAddDTO.setDirectlyUnderNumber(SafeKit.getInteger(getRandomValue("int",11)));
        return empChangesAddDTO;
    }


    /**
     * 生成update测试数据
     * @return EmpChangesUpdateDTO
     */
    public EmpChangesUpdateDTO getEmpChangesUpdateDTO(EmpChangesVO empChangesVO){
        return empChangesService.selectDOById(empChangesVO.getId(), SITE_ID).to(EmpChangesUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return EmpChangesQuery
     */
    public EmpChangesQuery getEmpChangesQuery() {
        EmpChangesQuery empChangesQuery = new EmpChangesQuery();
        List<EmpChangesDO> empChangesDOList = empChangesService.list(new EmpChangesDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(empChangesDOList)) {
            EmpChangesDO empChangesDO = empChangesDOList.get(0);
            empChangesQuery = empChangesDO.to(EmpChangesQuery.class);
            if (empChangesDO.getFormallyDate() != null) {
                empChangesQuery.setFormallyDateStart(DateKit.getBeforeDay(empChangesDO.getFormallyDate(),-1));
                empChangesQuery.setFormallyDateEnd(DateKit.getBeforeDay(empChangesDO.getFormallyDate(),1));
            }
            if (empChangesDO.getProbationDate() != null) {
                empChangesQuery.setProbationDateStart(DateKit.getBeforeDay(empChangesDO.getProbationDate(),-1));
                empChangesQuery.setProbationDateEnd(DateKit.getBeforeDay(empChangesDO.getProbationDate(),1));
            }
            if (empChangesDO.getRegularDate() != null) {
                empChangesQuery.setRegularDateStart(DateKit.getBeforeDay(empChangesDO.getRegularDate(),-1));
                empChangesQuery.setRegularDateEnd(DateKit.getBeforeDay(empChangesDO.getRegularDate(),1));
            }
            if (empChangesDO.getAdjustmentDate() != null) {
                empChangesQuery.setAdjustmentDateStart(DateKit.getBeforeDay(empChangesDO.getAdjustmentDate(),-1));
                empChangesQuery.setAdjustmentDateEnd(DateKit.getBeforeDay(empChangesDO.getAdjustmentDate(),1));
            }
            if (empChangesDO.getQuitDate() != null) {
                empChangesQuery.setQuitDateStart(DateKit.getBeforeDay(empChangesDO.getQuitDate(),-1));
                empChangesQuery.setQuitDateEnd(DateKit.getBeforeDay(empChangesDO.getQuitDate(),1));
            }
            if (empChangesDO.getPreQuitDate() != null) {
                empChangesQuery.setPreQuitDateStart(DateKit.getBeforeDay(empChangesDO.getPreQuitDate(),-1));
                empChangesQuery.setPreQuitDateEnd(DateKit.getBeforeDay(empChangesDO.getPreQuitDate(),1));
            }
            if (empChangesDO.getHandleQuitDate() != null) {
                empChangesQuery.setHandleQuitDateStart(DateKit.getBeforeDay(empChangesDO.getHandleQuitDate(),-1));
                empChangesQuery.setHandleQuitDateEnd(DateKit.getBeforeDay(empChangesDO.getHandleQuitDate(),1));
            }
            if (empChangesDO.getCompensation() != null) {
                empChangesQuery.setCompensationStart(SafeKit.getInteger(empChangesDO.getCompensation() - 1));
                empChangesQuery.setCompensationEnd(SafeKit.getInteger(empChangesDO.getCompensation() + 1));
            }
            if (empChangesDO.getPaymentLieuNotice() != null) {
                empChangesQuery.setPaymentLieuNoticeStart(SafeKit.getInteger(empChangesDO.getPaymentLieuNotice() - 1));
                empChangesQuery.setPaymentLieuNoticeEnd(SafeKit.getInteger(empChangesDO.getPaymentLieuNotice() + 1));
            }
            if (empChangesDO.getSsAttritionMonth() != null) {
                empChangesQuery.setSsAttritionMonthStart(DateKit.getBeforeDay(empChangesDO.getSsAttritionMonth(),-1));
                empChangesQuery.setSsAttritionMonthEnd(DateKit.getBeforeDay(empChangesDO.getSsAttritionMonth(),1));
            }
            if (empChangesDO.getPfAttritionMonth() != null) {
                empChangesQuery.setPfAttritionMonthStart(DateKit.getBeforeDay(empChangesDO.getPfAttritionMonth(),-1));
                empChangesQuery.setPfAttritionMonthEnd(DateKit.getBeforeDay(empChangesDO.getPfAttritionMonth(),1));
            }
            if (empChangesDO.getGmtCreate() != null) {
                empChangesQuery.setGmtCreateStart(DateKit.getBeforeDay(empChangesDO.getGmtCreate(),-1));
                empChangesQuery.setGmtCreateEnd(DateKit.getBeforeDay(empChangesDO.getGmtCreate(),1));
            }
            if (empChangesDO.getGmtModified() != null) {
                empChangesQuery.setGmtModifiedStart(DateKit.getBeforeDay(empChangesDO.getGmtModified(),-1));
                empChangesQuery.setGmtModifiedEnd(DateKit.getBeforeDay(empChangesDO.getGmtModified(),1));
            }
        }
        return empChangesQuery;
    }

    /**
     * 保存示例
     * @return EmpChangesVO
     */
    public EmpChangesVO saveEmpChangesExample(){
        EmpChangesAddDTO addDTO = this.getEmpChangesAddDTO();
        EmpChangesVO empChangesVO = empChangesService.save(addDTO,buildTokenUser());
        return empChangesVO;
    }


}

